/*
 * 普通的先进先出列出实现
 */
#include "TEight.h"
#include "TList.h"
#include <iostream>
using namespace std;

class CommonBFS:public TEight
{
public :
	CommonBFS(int * _orgin, int *_target):TEight(_orgin,_target)
	{

	}
	CommonBFS()
	{

	}
	bool repeat(TList<CommonBFS> &L) {
		int n = L.Getlen();
		for (int i = 0; i < n; i++)
			if (L.GetData(i) == *this)
				return true;;
		return false;
	}
	void printl(TList<CommonBFS> &L) {
		CommonBFS T = *this;
		if (T.last == -1)
			return;
		else {
			T = L.GetData(T.last);
			T.printl(L);
			T.printSelf();
		}
	}
	virtual void search()
	{
		 CommonBFS tBFS = *this;
		 TList<CommonBFS> tList;
		 tList.Append(tBFS);

		 int head =0,tail=0;
		 while(head <= tail)
		 {
			 for(int direction=0; direction<DirNum ; direction++)
			 {
				 tBFS = tList.GetData(head);
				// if(tBFS.hasExpand == true)
					// continue;
				 if(tBFS.extend(direction) && tBFS.repeat(tList)==false)
				 {
					 tBFS.last = head;//父结点
					// tBFS.hasExpand = true;
					 tList.Append(tBFS);
					 tail++;
				 }

				 if(tBFS.isFind() == true)
				 {
					 //找到了
					 cout<<"find!"<<endl;
					 tBFS.printl(tList);
					 tBFS.printSelf();
					 return;
				 }
			 }//if(head>10000)cout<<head<<" "<<tail<<endl;
			 head++;
		 }
		 cout<<"无解！"<<endl;
	}
};


